home *** CD-ROM | disk | FTP | other *** search
/ Hot Super Models / Hot Super Models.iso / unix / x11 / xv200.tar / xv-2.00 / xvinfo.c < prev    next >
C/C++ Source or Header  |  1992-01-02  |  8KB  |  280 lines

  1. /* 
  2.  * xvinfo.c - 'Info' box handling functions
  3.  *
  4.  * callable functions:
  5.  *
  6.  *   CreateInfo(geom)       -  creates the infoW window.  Doesn't map it.
  7.  *   InfoBox(vis)           -  random processing based on value of 'vis'
  8.  *                             maps/unmaps window, etc.
  9.  *   RedrawInfo(x,y,w,h)    -  called by 'expose' events
  10.  *   SetInfoMode(mode)      -  changes amount of info Info window shows
  11.  *   SetISTR(st, fmt, args) - sprintf's into ISTR #st.  Redraws it in window 
  12.  *   char *GetISTR(st)      - returns pointer to ISTR #st, or NULL if st bogus
  13.  */
  14.  
  15. /*
  16.  * Copyright 1989, 1990, 1991, 1992 by John Bradley and
  17.  *                       The University of Pennsylvania
  18.  *
  19.  * Permission to use, copy, and distribute for non-commercial purposes,
  20.  * is hereby granted without fee, providing that the above copyright
  21.  * notice appear in all copies and that both the copyright notice and this
  22.  * permission notice appear in supporting documentation.
  23.  *
  24.  * The software may be modified for your own purposes, but modified versions
  25.  * may not be distributed.
  26.  *
  27.  * This software is provided "as is" without any expressed or implied warranty.
  28.  *
  29.  * The author may be contacted via:
  30.  *    US Mail:   John Bradley
  31.  *               GRASP Lab, Room 301C
  32.  *               3401 Walnut St.
  33.  *               Philadelphia, PA  19104
  34.  *
  35.  *    Phone:     (215) 898-8813
  36.  *    EMail:     bradley@cis.upenn.edu
  37.  */
  38.  
  39.  
  40. #define  NEEDSVARARGS
  41.  
  42. #include "xv.h"
  43. #include "bitmaps.h"
  44.  
  45. /* max length of an Info String */
  46. #define ISTRLEN 80
  47.  
  48. /* baseline of top line of text */
  49. #define TOPBASE (36 + penn_height/2 + 4 + 8 + ASCENT)
  50. #define STLEFT  100   /* left edge of strings */
  51.  
  52. static Pixmap graspPix, pennPix;
  53. static char istrs[NISTR][ISTRLEN];
  54.  
  55. #ifdef __STDC__
  56. static void DrawStrings(void);
  57. static void DrawFieldName(int);
  58. static void RedrawString(int);
  59. #else
  60. static void DrawStrings(), DrawFieldName(), RedrawString();
  61. #endif
  62.  
  63.  
  64.  
  65. /***************************************************/
  66. void CreateInfo(geom)
  67. char *geom;
  68. {
  69.   XClassHint classh;
  70.   CARD32     data[2];
  71.   Atom       prop;
  72.  
  73.   infoW = CreateWindow("xv info", geom, INFOWIDE, INFOHIGH, infofg, infobg);
  74.   if (!infoW) FatalError("can't create info window!");
  75.  
  76.   classh.res_name = "xv";
  77.   classh.res_class = "XVinfo";
  78.   XSetClassHint(theDisp, infoW, &classh);
  79.  
  80.   data[0] = (CARD32)XInternAtom(theDisp, "WM_DELETE_WINDOW", FALSE);
  81.   data[1] = (CARD32)time((long *)0);
  82.   prop = XInternAtom(theDisp, "WM_PROTOCOLS", FALSE),
  83.  
  84.   XChangeProperty(theDisp, infoW, prop, prop,
  85.           32, PropModeReplace, (unsigned char *) data, 2);
  86.  
  87.   pennPix = XCreatePixmapFromBitmapData(theDisp, infoW, penn_bits, penn_width, 
  88.                   penn_height, infofg, infobg, dispDEEP);
  89.   graspPix = XCreatePixmapFromBitmapData(theDisp,infoW,grasp_bits,grasp_width, 
  90.                   grasp_height, infofg, infobg, dispDEEP);
  91. }
  92.   
  93.  
  94. /***************************************************/
  95. void InfoBox(vis)
  96. int vis;
  97. {
  98.   if (vis) XMapRaised(theDisp, infoW);
  99.   else     XUnmapWindow(theDisp, infoW);
  100.  
  101.   infoUp = vis;
  102. }
  103.  
  104.  
  105. /***************************************************/
  106. void RedrawInfo(x,y,w,h)
  107. int x,y,w,h;
  108. {
  109.   int  i;
  110.   XRectangle xr;
  111.  
  112.   xr.x = x;  xr.y = y;  xr.width = w;  xr.height = h;
  113.   XSetClipRectangles(theDisp, theGC, 0,0, &xr, 1, Unsorted);
  114.  
  115.   XSetForeground(theDisp, theGC, infofg);
  116.   XSetBackground(theDisp, theGC, infobg);
  117.  
  118.   /* draw the two icons */
  119.   XCopyArea(theDisp, pennPix, infoW, theGC, 0, 0, penn_width, penn_height,
  120.         36 - penn_width/2, 36 - penn_height/2);
  121.   XCopyArea(theDisp, graspPix, infoW, theGC, 0, 0, grasp_width, grasp_height,
  122.         INFOWIDE - 36 - grasp_width/2, 36 - grasp_height/2);
  123.  
  124.   /* draw the credits */
  125.   sprintf(str,"XV   -   %s",REVDATE);
  126.   CenterString(infoW, str, INFOWIDE/2, 36-LINEHIGH);
  127.   CenterString(infoW, "by John Bradley  (bradley@cis.upenn.edu)"
  128.            , INFOWIDE/2, 36);
  129.   CenterString(infoW, "Copyright 1989-1992, University of Pennsylvania",
  130.            INFOWIDE/2, 36+LINEHIGH);
  131.  
  132.   /* draw the dividing lines */
  133.   i = 36 + penn_height/2 + 4;
  134.   XDrawLine(theDisp, infoW, theGC, 0, i, INFOWIDE, i);
  135.   XDrawLine(theDisp, infoW, theGC, 0, i+2, INFOWIDE, i+2);
  136.  
  137.   XDrawLine(theDisp, infoW, theGC, 0, INFOHIGH-20, INFOWIDE, INFOHIGH-20);
  138.   XDrawLine(theDisp, infoW, theGC, 0, INFOHIGH-22, INFOWIDE, INFOHIGH-22);
  139.  
  140.   XDrawLine(theDisp, infoW, theGC, 0, INFOHIGH-40, INFOWIDE, INFOHIGH-40);
  141.   XDrawLine(theDisp, infoW, theGC, 0, INFOHIGH-42, INFOWIDE, INFOHIGH-42);
  142.  
  143.   DrawStrings();
  144.   XSetClipMask(theDisp, theGC, None);
  145. }
  146.  
  147.  
  148. /***************************************************/
  149. static void DrawStrings()
  150. {
  151.   int i;
  152.   for (i=0; i<6; i++) DrawFieldName(i);     /* draw the field titles */
  153.   for (i=0; i<NISTR; i++) RedrawString(i);  /* draw the field values */
  154.   XFlush(theDisp);
  155. }
  156.  
  157.  
  158. /***************************************************/
  159. static void DrawFieldName(fnum)
  160. int fnum;
  161. {
  162.   static char *fname[6] = {  "Filename:", "Format:", "Resolution:", 
  163.                  "Cropping:", "Expansion:", "Colors:" };
  164.  
  165.   XSetForeground(theDisp, theGC, infofg);
  166.   XSetBackground(theDisp, theGC, infobg);
  167.  
  168.   if (infoMode == INF_NONE || infoMode == INF_STR) return;
  169.   if (infoMode == INF_PART && fnum>=3) return;
  170.  
  171.   XDrawString(theDisp, infoW, theGC, 10, TOPBASE + fnum*LINEHIGH, 
  172.         fname[fnum], strlen(fname[fnum]));
  173. }
  174.  
  175.  
  176. /***************************************************/
  177. static void RedrawString(st)
  178. int st;
  179. {
  180.   /* erase area of string, and draw it with new contents */
  181.   
  182.   if (infoMode == INF_NONE) return;
  183.   if (infoMode == INF_STR && st > ISTR_WARNING) return;
  184.   if (infoMode == INF_PART && st > ISTR_RES) return;
  185.  
  186.  
  187.   if (st == ISTR_INFO) {
  188.     XSetForeground(theDisp, theGC, infobg);
  189.     XFillRectangle(theDisp, infoW, theGC, 0, INFOHIGH-39, INFOWIDE, 17);
  190.     XSetForeground(theDisp, theGC, infofg);
  191.     CenterString(infoW, istrs[st], INFOWIDE/2, INFOHIGH-31);
  192.   }
  193.   else if (st == ISTR_WARNING) {
  194.     XSetForeground(theDisp, theGC, infobg);
  195.     XFillRectangle(theDisp, infoW, theGC, 0, INFOHIGH-19, INFOWIDE, 17);
  196.     XSetForeground(theDisp, theGC, infofg);
  197.     CenterString(infoW, istrs[st], INFOWIDE/2, INFOHIGH-10);
  198.   }
  199.   else {
  200.     XSetForeground(theDisp, theGC, infobg);
  201.     XFillRectangle(theDisp, infoW, theGC, 
  202.            STLEFT, TOPBASE - ASCENT + (st-ISTR_FILENAME)*LINEHIGH, 
  203.            INFOWIDE-STLEFT, LINEHIGH);
  204.     XSetForeground(theDisp, theGC, infofg);
  205.     XDrawString(theDisp, infoW, theGC, STLEFT,TOPBASE
  206.         + (st-ISTR_FILENAME)*LINEHIGH,    istrs[st], strlen(istrs[st]));
  207.   }
  208. }
  209.  
  210.  
  211.  
  212. /***************************************************/
  213. void SetInfoMode(mode)
  214. int mode;
  215. {
  216.   int y1, y2;
  217.  
  218.   infoMode = mode;
  219.   if (infoUp) {   /* only do this if window is mapped */
  220.     y1 = TOPBASE - ASCENT;
  221.     y2 = INFOHIGH-43;
  222.  
  223.     XSetForeground(theDisp, theGC, infobg);
  224.  
  225.     XFillRectangle(theDisp, infoW, theGC, 0, y1, INFOWIDE, y2-y1);
  226.     XFillRectangle(theDisp, infoW, theGC, 0, INFOHIGH-39, INFOWIDE, 17);
  227.     XFillRectangle(theDisp, infoW, theGC, 0, INFOHIGH-19, INFOWIDE, 17);
  228.  
  229.     DrawStrings();
  230.   }
  231. }
  232.  
  233.  
  234. /***************************************************/
  235. /*VARARGS0*/
  236. void SetISTR(va_alist)
  237. va_dcl
  238. {
  239.   va_list args;
  240.   char    *fmt;
  241.   int     stnum;
  242.  
  243.   /* InfoStr( ISTR, format, arg1, arg2, ...) */
  244.  
  245.   va_start(args);
  246.  
  247.   stnum = va_arg(args, int);
  248.   if (stnum<0 || stnum>=NISTR) return;
  249.  
  250.   fmt = va_arg(args, char *);
  251.   vsprintf(istrs[stnum], fmt, args);
  252.   va_end(args);
  253.   
  254.   if (infoUp) {
  255.     RedrawString(stnum);
  256.     XFlush(theDisp);
  257.   }
  258.  
  259.   if (stnum == ISTR_COLOR) 
  260.     SetISTR(ISTR_INFO,"%s  %s", formatStr, istrs[ISTR_COLOR]);
  261.  
  262.  
  263.   if (ctrlUp && (stnum == ISTR_INFO || stnum == ISTR_WARNING)) {
  264.     DrawCtrlStr();
  265.     XFlush(theDisp);
  266.   }
  267. }
  268.  
  269.  
  270. /***************************************************/
  271. char *GetISTR(stnum)
  272. int stnum;
  273. {
  274.   /* returns pointer to ISTR string */
  275.   if (stnum < 0 || stnum>=NISTR) return(NULL);
  276.   return (istrs[stnum]);
  277. }
  278.  
  279.  
  280.